<?php
namespace Personnelsystem\Controller;
use Think\Controller;
header("content-type:text/html;charset=utf-8");
class VariablesController extends LoginTrueController {
    public function __construct()
    {
        parent::__construct();
        $this->LoginIsSystem();
    }
    public function lists(){
        $this->LoginTrue();
        $variables=M("variables");
        $rs_variables=$variables->select();
        $this->assign("rs_variables",$rs_variables);
        $this->display();
    }
    public function update(){
        $vId=$_GET["vId"];
        $variables=M("variables");
        $rs_variables=$variables->where("vId={$vId}")->find();
		
		$val=unserialize(stripslashes($rs_variables['vVariablesVal']));

        $this->assign("rs_variables",$rs_variables);
		$this->assign("valcn",implode('|',$val['cn']));
		$this->assign("valug",implode('|',$val['ug']));
		$this->assign("valkk",implode('|',$val['kk']));
        $this->display();
    }
    public function UpdateAction(){
        $vId=$_GET["vId"];
        $variables=M("variables");
        $data["vNum"]=$_POST["vNum"];
        $data["vVariablesExplain"]=$_POST["vVariablesExplain"];
		$cnVal=explode("|",$_POST["vCNVariablesVal"]);  //汉语
		$ugVal=explode("|",$_POST["vUGVariablesVal"]);	//维语
		$kkVal=explode("|",$_POST["vKKVariablesVal"]);	//哈语
		
        $data["vVariables"]=$_POST["vVariables"];
        $data["vVariablesVal"]=addslashes(serialize(array("cn"=>$cnVal,"ug"=>$ugVal,"kk"=>$kkVal)));  //将 不同语言存入数组，并序列号和转义后存入字符串
        $result=$variables->where("vId={$vId}")->save($data);
        if($result){
            $this->success("更新成功");
        }else{
            $this->error("更新失败");
        }
    }
    
}